#pragma once

#include "cyberrt_reader.h"
#include "cyberrt_writer.h"

#include <functional>
#include <memory>
#include <string>

class CyberrtNode
{
public:
    CyberrtNode(const std::string &node_name)
    {
        m_node = apollo::cyber::CreateNode(node_name);
    };
    ~CyberrtNode(){};

public:
    template <typename MessageT>
    std::shared_ptr<CyberrtReader<MessageT>> createReader(const std::string                                           &channel,
                                                          std::function<void(const std::shared_ptr<const MessageT> &)> callback) const
    {
        return std::make_shared<CyberrtReader<MessageT>>(m_node->CreateReader<MessageT>(channel, callback));
    }

    template <typename MessageT>
    std::shared_ptr<CyberrtWriter<MessageT>> createWriter(const std::string &channel) const
    {
        return std::make_shared<CyberrtWriter<MessageT>>(m_node->CreateWriter<MessageT>(channel));
    }

private:
    std::unique_ptr<apollo::cyber::Node> m_node;
};